﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>商品分类设置</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/jquery.Jcrop.js"></script>
    <link href="~/Content/Script/jquery.Jcrop.css" rel="stylesheet" />
    <script src="~/Content/layer/layer.js"></script>
    <link href="~/Content/layer/skin/default/layer.css" rel="stylesheet" />
    <script>
        $(function () {
            //GetMer();
            initTable();
            //$('#btnadd').linkbutton('disable');
            //$('#btnedit').linkbutton('disable');
            //$('#btndell').linkbutton('disable');
            $('#xianshiPic').dialog({
                onClose: function () {
                    $("#fileDiv").remove();
                    $("#tp1Div").remove();
                    $("#picwenjian1").hide();
                }
            });
        });

        var Mer;
        var diplayText;
        //获取商户
        function GetMer() {
            var grid = $('#SearchMer').combogrid({
                panelWidth: 500,
                idField: 'MerID',
                textField: 'MerName',
                url: '/Order_DishesType/getMer',
                method: 'post',
                pageSize: 5,
                pageList: [5],
                pagination: true,
                rownumbers: true,
                fitColumns: true,
                columns: [[
                    { field: 'MerID', title: '商户ID', width: 80, align: 'center' },
                    { field: 'MerName', title: '商户名称', width: 80, align: 'center' },
                    { field: 'MerTxt', title: '商户介绍', width: 120, align: 'center' },
                    { field: 'MerAdr', title: '商户地址', width: 80, align: 'center' },
                    { field: 'MerCall', title: '商户联系电话', width: 80, align: 'center' }
                ]],
                onSelect: function (index, row) {
                    diplayText = row[grid.combogrid('options').textField];
                    Mer = $('#SearchMer').combogrid("getValue");//获取操作员
                    //加载对应的商品分类
                    initTable(Mer);
                    //控制增删查改的权限
                    $.post("/Order_DishesType/getPower", function (database) {
                        if (database != "") {
                            if (database.Add == 1) {
                                $('#btnadd').linkbutton('enable');
                            }
                            if (database.Dell == 1) {
                                $('#btndell').linkbutton('enable');
                            }
                            if (database.Edit == 1) {
                                $('#btnedit').linkbutton('enable');
                            }
                        }
                    })
                },
                onLoadSuccess: function () {
                    //分页后判断下是否有选中的数据行，combogrid会依据上一次选中的值进行初始化，选中datagrid数据行和设置显示值
                    if (!grid.combogrid('grid').datagrid('getSelected'))//不在当前页
                    {
                        $('#SearchMer').combogrid("setValue", diplayText);
                    }
                }
            });
        }

        //获取一级商品分类对应的表格
        function initTable() {
            $('#View').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                singleSelect: true,
                striped: true,
                url: '/Order_DishesType/getgrids',
                sortName: 'Postion',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'DishesTypeID',
                pageSize: 20,
                pageList: [20],
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'DishesTypeID', title: 'ID', width: 70, sortable: true, hidden: true },
                    { field: 'DishesTypeName', title: '一级分类名称', width: 90, sortable: true },
                    { field: 'Postion', editor: 'text', title: '标志', width: 70, sortable: true, hidden: true },
                    {
                        field: 'px', title: '排序', width: 80, align: 'center', formatter: function (value, row) {
                            return '<input id="PostionID' + row.DishesTypeID + '" value=' + row.Postion + ' style="width: 25px;text-align: center;" type="text" onchange="Postion_Sort(' + row.DishesTypeID + ')">';
                            //return '<a href="javascript:void(MoveUp())" >上移</a>     <a href="javascript:void(MoveDown())">下移</a>';
                        },
                    }
                ]],
                toolbar: '#tb1',
                onSelect: function (index, row) {
                    //加载对应的商品分类
                    initTables(row.DishesTypeID);
                }
            });
        }

        function initTables(item) {
            $('#Views').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                singleSelect: true,
                striped: true,
                url: '/Order_DishesType/getgridss?DishesTypeID=' + item,
                sortName: 'Postion',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'DishesTypeID',
                pageSize: 20,
                pageList: [20],
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'DishesTypeID', title: 'ID', width: 70, sortable: true, hidden: true },
                    { field: 'DishesTypeName', title: '二级分类名称', width: 90, sortable: true },
                    { field: 'Postion', title: '标志', width: 70, sortable: true, hidden: true },
                    {
                        field: 'tpsc', title: '图片上传', width: 100, sortable: true, align: 'center', formatter: function (value, row) {
                            return '<a href="#" onclick="downloadPic(' + row.DishesTypeID + ')">上传照片</a>';
                            //return '<a href="#" onclick="downloadPic(' + row.DishesTypeID + ')">上传照片</a>    <a href="javascript:void(MoveUps())" >上移</a>     <a href="javascript:void(MoveDowns())">下移</a>';
                        }
                    },
                    {
                        field: 'px', title: '排序', width: 80, sortable: true, align: 'center', formatter: function (value, row) {
                            return '<input id="PostionID' + row.DishesTypeID + '" value=' + row.Postion + ' style="width: 25px;text-align: center;" type="text" onchange="Postion_Sort(' + row.DishesTypeID + ')">';
                        }
                    }
                ]],
                toolbar: '#tb2',
            });
        }

        //获取该商户二级分类的图片
        function downloadPic(DishesTypeID) {
            $("#DishesTypeID_pic").text(DishesTypeID);
            $("#fileToUpload").val("");
            //$("#uploadFile").hide();

            $("#tishiyu").html("当前图片");
            //$("#tp1").attr("src", "");
            var file = "<div id=\"tp1Div\" align=\"center\" style=\"margin:auto;width:300px;padding: 10px;\"><img id=\"tp1\" style=\"border-style:solid; border-width:1px; border-color:#000;\" src=\"\" /></div>"
                + "<div id=\"fileDiv\" align=\"center\" style=\"padding: 10px;\"><input  id=\"f\" onchange=\"imgFun(this.id, this.value, this.files)\" type=\"file\" /></div>";

            //$.post("/MerSet/Image?id=" + MerID, function (src) {
            //    gaib(src);
            //})
            $.get("/Order_DishesType/getDishesTypePhoto?DishesTypeID=" + DishesTypeID, function (data) {
                //console.log(data);
                //var myDate = new Date();
                //var shij = myDate.getTime();
                $("#tp1").attr("src", data);
                //    $("#UploadPic").dialog("open").dialog("setTitle", "上传图片");
            });
            $("#picwenjian").append(file);
            $("#xianshiPic").dialog("open");
        };

        function imgFun(id, value, fi) {
            $("#picwenjian1").show()
            $("#tishiyu").html("请选择要上传的部分");
            var fielObj = document.getElementById(id)
            var aa = value;
            if (aa.match(/.jpg|.gif|.png|.bmp/i)) {
                //console.log(1);
            }
            var fiel = fi[0];
            //console.log(fiel);
            //console.log(fielObj);
            var img1 = document.getElementById("tp1")
            //var img2 = document.getElementById("tp2")
            var windowURL = window.URL || window.webkitURL;
            //console.log(windowURL);
            var dataURL = windowURL.createObjectURL(fi[0]);
            img1.src = dataURL;
            //img2.src = dataURL;
            //console.log(img1.src);
            $('#tp1').Jcrop({
                bgFade: true,
                onSelect: updatePreview,
                //onSelect: gaib,
                aspectRatio: 1.3,
                //allowSelect: false,
                //allowResize: false,
                //maxSize: [120, 120],
                minSize: [230, 230],
                boxWidth: 320,
                //boxHeight:350,
                getScaleFactor: [700, 300],
                setSelect: [230, 230, 0, 0],

            });

        };

        function updatePreview(c) {
            wenjian = document.getElementById('f').files[0].name;
            date = {
                x: Math.ceil(c.x),
                y: Math.ceil(c.y),
                w: Math.ceil(c.w),
                h: Math.ceil(c.h),
                pw: Math.ceil($('#tp1').width()),
                ph: Math.ceil($('#tp1').height()),
                t: wenjian,
                id: $("#DishesTypeID_pic").text(),
            };
            //console.log(date);
        };

        function quedPic() {
            var picname = document.getElementById('f').files[0];
            var fd = new FormData();
            var xhr = new XMLHttpRequest();
            fd.append("fileToUpload", picname);
            fd.append("id", $("#DishesTypeID_pic").text());
            xhr.open("POST", "/Order_DishesType/ToLead");
            xhr.send(fd);
            setTimeout(function () {
                if (date.w >= 230 || date.h >= 230) {
                    $.post("/Order_DishesType/SaveImg", date, function (da) {
                        if (da = 1) {
                            uploadFile(date.t);
                        };
                    });
                } else {
                    alert("请选择图片进行裁剪");
                }
            }, 200);
        };

        //选择图片
        function fileSelected(sourceId, targetId) {
            console.log("123");
            if (typeof FileReader == 'undefined') {
                $.messager.alert("请选择图片");
                return;
            }
            var reader = new FileReader();
            reader.onload = function (e) {
                var img = document.getElementById(targetId);
                img.src = this.result;
            }
            reader.readAsDataURL(document.getElementById(sourceId).files[0]);
            var file = document.getElementById('fileToUpload').files[0];
            var fileName = file.name;
            var file_typename = fileName.substring(fileName.lastIndexOf('.'), fileName.length);
            filePath = "/DishesTypes/" + fileName;
            if (file_typename == '.jpg') {
                //这里限定上传文件文件类型
                if (file) {
                    $("#uploadFile").show();
                    var fileSize = 0;
                    if (file.size > 1024 * 1024) {
                        fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
                    }
                    else {
                        fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
                    }
                }
            } else {
                $("#uploadFile").hide();
                document.getElementById('fileName').innerHTML = "<span style='color:Red'>只能是jpg格式的图片</span>"
            }
        }

        //上传文件
        function uploadFile(name) {
            ///var picname = document.getElementById('fileToUpload').files[0].name;
            var dishestypeid_pic = $("#DishesTypeID_pic").text();
            $.get("/Order_DishesType/ToLoadPic?DishesTypeID=" + dishestypeid_pic + "&PicName=" + name, function (data) {
                //console.log(data);
                if (data == "1") {
                    //$('#dlg_progress').dialog('open');
                    //var fd = new FormData();
                    //fd.append("fileToUpload", document.getElementById('fileToUpload').files[0]);
                    //var xhr = new XMLHttpRequest();
                    //xhr.upload.addEventListener("progress", uploadProgress, false);
                    //xhr.addEventListener("load", uploadComplete, false);
                    //xhr.addEventListener("error", uploadFailed, false);
                    //xhr.addEventListener("abort", uploadCanceled, false);
                    //xhr.open("POST", "/MerSet/ToLead");
                    //xhr.send(fd);
                    //$('#dlg_progress').dialog('close');//关闭进度条
                    $('#xianshiPic').dialog('close');//关闭图片上传界面
                    $.messager.alert("友情提示", "图片上传成功");
                    //window.location.href = "/MerSet/index";
                    initTable();
                    $('#Views').datagrid('reload');
                } else {
                    $.messager.alert("友情提示", data);
                }
            });
        }

        //添加商品分类对话框
        function AddDialog() {
            ClearText();
            $('#editDialog').dialog('open').dialog('setTitle', '新增一级商品分类');
        }

        function AddDialog2() {
            var checkdata = $("#View").datagrid("getSelections")[0];
            $("#DishesTypeID").val("");
            $("#DishesTypeNames").val(checkdata.DishesTypeName);
            $("#PantID").val(checkdata.DishesTypeID);
            $("#DishesTypeNamess").val("");
            $('#editDialog2').dialog('open').dialog('setTitle', '新增二级商品分类');
        }

        //修改商品分类对话框
        function UpdateDialog() {
            var UpdateInfoID = $("#View").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#editDialog").dialog("open").dialog("setTitle", "修改一级商品分类");
                BingUpdate();
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        function UpdateDialog2() {
            var UpdateInfoID = $("#Views").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#editDialog2").dialog("open").dialog("setTitle", "修改二级商品分类");
                BingUpdate2();
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //获取修改商品分类信息
        function BingUpdate() {
            //首先获取选中的一级商品分类的信息
            var checkdata = $("#View").datagrid("getSelections")[0];
            $("#DishesTypeID").textbox('setValue', checkdata.DishesTypeID);
            $("#DishesTypeName").val(checkdata.DishesTypeName);
            $("#Postion").val(checkdata.Postion);
        }

        function BingUpdate2() {
            //首先获取选中的二级商品分类的信息
            var checkdata = $("#View").datagrid("getSelections")[0];
            $("#DishesTypeNames").val(checkdata.DishesTypeName);

            var checkdata2 = $("#Views").datagrid("getSelections")[0];
            $("#DishesTypeID").textbox('setValue', checkdata2.DishesTypeID)
            $("#DishesTypeNamess").val(checkdata2.DishesTypeName);
            $("#PantID").val(checkdata2.PantID);
            $("#Postion").val(checkdata2.Postion);
        }

        //删除用户注册配置
        function DeleteDialog() {
            //获取到商品分类ID
            //首先获取选中的商品分类的所有信息
            var checkdata = $("#View").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#View").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    DishesTypeID: checkdata.DishesTypeID,
                    DishesTypeName: checkdata.DishesTypeName,
                    PantID: checkdata.PantID,
                    Postion: checkdata.Postion,
                };
                //获取商品二级菜单的数据
                $.post("/Order_DishesType/getgridss?DishesTypeID=" + postdata.DishesTypeID, function (data) {
                    //console.log(data.total);
                    if (data.total <= 0) {
                        //发送异步请求删除数据
                        $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + checkdata.DishesTypeName + "</font>这个商品分类吗？", function (del) {
                            if (del) {
                                $.post("/Order_DishesType/UpdateOrder_DishesType?Tag=" + 3, postdata, function (data) {
                                    if (data == "1") {
                                        $.messager.alert("友情提示", "删除成功");
                                        initTable(Mer);
                                    }
                                    else {
                                        $.messager.alert("友情提示", "删除失败:" + data);
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.messager.alert("友情提示", "请先删除右边二级菜单数据，共有 <font color='red' size='6'>" + data.total + "</font> 条数据");
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
            }
        }

        function DeleteDialog2() {
            //获取到商品分类ID
            //首先获取选中的商品分类的所有信息
            var checkdata = $("#Views").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#Views").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    DishesTypeID: checkdata.DishesTypeID,
                    DishesTypeName: checkdata.DishesTypeName,
                    Postion: checkdata.Postion,
                    PantID: checkdata.PantID,
                };
                //获取商品二级菜单的商品数据
                $.post("/Order_Dishes/getgrid?DishesTypeID=" + postdata.DishesTypeID, function (data) {
                    if (data.total <= 0) {
                        //发送异步请求删除数据
                        $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + checkdata.DishesTypeName + "</font>这个商品分类吗？", function (del) {
                            if (del) {
                                $.post("/Order_DishesType/UpdateOrder_DishesType2?Tag=" + 3, postdata, function (data) {
                                    if (data == "1") {
                                        $.messager.alert("友情提示", "删除成功");
                                        initTables(postdata.PantID);
                                    }
                                    else {
                                        $.messager.alert("友情提示", "删除失败:" + data);
                                    }
                                });
                            }
                        });
                    }
                    else {
                        $.messager.alert("友情提示", "请先删除二级菜单下的商品数据，共有 <font color='red' size='6'>" + data.total + "</font> 条数据");
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
            }
        }
        //保存
        function submitForm() {
            //首先判断前台的验证是否通过
            var valid = $('#editController').form('validate');
            if (valid == false) {
                return false;
            }
            var postdata = {
                DishesTypeID: $("#DishesTypeID").val(),
                DishesTypeName: $("#DishesTypeName").val(),
                Postion: $("#Postion").val(),
            };

            //使用异步实现获取商品一级分类名称
            $.post("/Order_DishesType/getDishesTypeByName?DishesTypeName=" + postdata.DishesTypeName, function (reg) {
                //console.log(postdata.DishesTypeName);
                //console.log(reg);
                if (reg == true) {
                    var Tag = 1;
                    if (postdata.DishesTypeID != "") {
                        Tag = 2;
                    }
                    //使用异步实现修改用户信息
                    $.post("/Order_DishesType/UpdateOrder_DishesType?Tag=" + Tag, postdata, function (date) {
                        if (date == "1") {
                            $("#editDialog").dialog('close');
                            $.messager.alert("友情提示", "操作成功");
                            //$("#View").datagrid('reload');
                            initTable();
                        }
                        else {
                            $.messager.alert("友情提示", "修改失败，请检查");
                        }
                    });
                }
                else {
                    $.messager.alert("友情提示", "修改失败，请检查名称是否存在重名");
                }
            });
        }

        function submitForm2() {
            //首先判断前台的验证是否通过
            var valid = $('#editController').form('validate');
            if (valid == false) {
                return false;
            }
            var postdata = {
                DishesTypeID: $("#DishesTypeID").val(),
                DishesTypeName: $("#DishesTypeNamess").val(),
                PantID: $("#PantID").val(),
                Postion: $("#Postion").val(),
            };
            //使用异步实现获取商品二级分类名称
            $.post("/Order_DishesType/getDishesTypeByName2?DishesTypeName=" + postdata.DishesTypeName, function (reg) {
                //console.log(postdata.DishesTypeName);
                //console.log(reg);
                if (reg == true) {
                    var Tag = 1;
                    if (postdata.PantID != "" && postdata.DishesTypeID != "") {
                        Tag = 2;
                    }
                    //使用异步实现修改用户信息
                    $.post("/Order_DishesType/UpdateOrder_DishesType2?Tag=" + Tag + '&PantID=' + PantID, postdata, function (date) {
                        if (date == "1") {
                            $("#editDialog2").dialog('close');
                            $.messager.alert("友情提示", "操作成功");
                            $("#Views").datagrid('reload');
                        }
                        else {
                            $.messager.alert("友情提示", "修改失败，请检查");
                        }
                    });
                }
                else {
                    $.messager.alert("友情提示", "修改失败，请检查名称是否存在重名");
                }
            });
        }

        //清空文本框中的值
        function ClearText() {
            $("#DishesTypeID").textbox('setValue', "");
            $("#DishesTypeName").val("");
            //$("#IntBZ").textbox('setValue',"");
            //$("#MerID").val(diplayText);
        }

        //一级商品分类上移
        function MoveUp() {
            //console.log("up");
            var row = $("#View").datagrid('getSelected');
            //console.log(row);
            var index = $("#View").datagrid('getRowIndex', row);
            //console.log(index);
            mysort(index, 'up', 'View', row.Postion);
        }
        //一级商品分类下移
        function MoveDown() {
            var row = $("#View").datagrid('getSelected');
            var index = $("#View").datagrid('getRowIndex', row);
            mysort(index, 'down', 'View', row.Postion);
        }
        //二级商品分类上移
        function MoveUps() {
            //console.log("up");
            var row = $("#Views").datagrid('getSelected');
            //console.log(row);
            var index = $("#Views").datagrid('getRowIndex', row);
            //console.log(index);
            mysort(index, 'up', 'Views', row.Postion);
        }
        //二级商品分类下移
        function MoveDowns() {
            var row = $("#Views").datagrid('getSelected');
            var index = $("#Views").datagrid('getRowIndex', row);
            mysort(index, 'down', 'Views', row.Postion);
        }
        //上下移动方法
        function mysort(index, type, gridname, postion) {
            if ("up" == type) {
                if (index != 0) {
                    var toup = $('#' + gridname).datagrid('getData').rows[index];
                    var todown = $('#' + gridname).datagrid('getData').rows[index - 1];

                    $.ajax({
                        //要用post方式
                        type: "POST",
                        //方法所在页面和方法名
                        url: "/Order_DishesType/UpdateDishesTypePostion",
                        data: "{dishestypeidup:'" + toup.DishesTypeID + "',dishestypeiddown:'" + todown.DishesTypeID + "',postionup:'" + (postion - 1) + "',postiondown:'" + postion + "'}", //带参数的,参数名称abc,参数“111”
                        //date:"{}",//没有参数的初始化
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if (data == "1") {
                                $('#' + gridname).datagrid('getData').rows[index] = todown;
                                $('#' + gridname).datagrid('getData').rows[index - 1] = toup;
                                $('#' + gridname).datagrid('refreshRow', index);
                                $('#' + gridname).datagrid('refreshRow', index - 1);
                                $('#' + gridname).datagrid('selectRow', index - 1);
                                initTable();
                                initTables(toup.DishesTypeID);
                            } else {
                                $.messager.alert("友情提示", "上移失败！");
                            }
                        }
                    });
                }
            } else if ("down" == type) {
                var rows = $('#' + gridname).datagrid('getRows').length;
                if (index != rows - 1) {
                    var todown = $('#' + gridname).datagrid('getData').rows[index];
                    var toup = $('#' + gridname).datagrid('getData').rows[index + 1];

                    $.ajax({
                        //要用post方式
                        type: "POST",
                        //方法所在页面和方法名
                        url: "/Order_DishesType/UpdateDishesTypePostion",
                        data: "{dishestypeidup:'" + toup.DishesTypeID + "',dishestypeiddown:'" + todown.DishesTypeID + "',postionup:'" + postion + "',postiondown:'" + (postion + 1) + "'}", //带参数的,参数名称abc,参数“111”
                        //date:"{}",//没有参数的初始化
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if (data == "1") {
                                $('#' + gridname).datagrid('getData').rows[index + 1] = todown;
                                $('#' + gridname).datagrid('getData').rows[index] = toup;
                                $('#' + gridname).datagrid('refreshRow', index);
                                $('#' + gridname).datagrid('refreshRow', index + 1);
                                $('#' + gridname).datagrid('selectRow', index + 1);
                                initTable();
                                initTables(toup.DishesTypeID);
                            } else {
                                $.messager.alert("友情提示", "下移失败！");
                            }
                        }
                    });
                }
            }
        }

        //商品分类一二级排序
        function Postion_Sort(DishesTypeID) {
            var PostionID = ("PostionID" + DishesTypeID).split(',', 1);
            var Postion = $("#" + PostionID).val();
            if (DishesTypeID != null && Postion != null) {
                $.ajax({
                    type: 'post',
                    data: { DishesTypeID: DishesTypeID, Postion: Postion },
                    url: '/Order_DishesType/UpdateDishesTypeSort',
                    //async: false,
                    success: function (result) {
                        if (result == 1) {
                            //$.messager.show("友情提示", "排序成功");
                            layer.msg('排序成功');
                            $("#View").datagrid('reload');
                            $("#Views").datagrid('reload');
                        } else {
                            //发生错误，应弹框提示
                            $.messager.alert("友情提示", "排序失败" + result);
                        }
                    }
                });
            }
        }

    </script>
</head>
<body style="padding: 0;">
    @*<div style="padding:5px; background-color:#F4F4F4">
            <div >
                <a>商户：</a>
                <input id="SearchMer" class="easyui-combogrid" style="width: 120px" />
            </div>
        </div>*@

    <table>
        <tr>
            <td><table id="View"></table></td>
            <td></td>
            <td><table id="Views"></table></td>
        </tr>
    </table>
    <div id="tb1" style="background-color:#F4F4F4">
        <div style="margin-bottom: 5px">
            <a href="#" id="btnadd" class="easyui-linkbutton" iconcls="icon-add" onclick="AddDialog()" plain="true">新增一级菜单</a>
            <a href="#" id="btnedit" class="easyui-linkbutton" iconcls="icon-edit" onclick="UpdateDialog()" plain="true">修改一级菜单</a>
            <a href="#" id="btndell" class="easyui-linkbutton" iconcls="icon-cancel" onclick="DeleteDialog()" plain="true">删除一级菜单</a>
        </div>
    </div>
    <div id="tb2" style="background-color:#F4F4F4;display:none;">
        <div style="margin-bottom: 5px">
            <a href="#" id="btnadd" class="easyui-linkbutton" iconcls="icon-add" onclick="AddDialog2()" plain="true">新增二级菜单</a>
            <a href="#" id="btnedit" class="easyui-linkbutton" iconcls="icon-edit" onclick="UpdateDialog2()" plain="true">修改二级菜单</a>
            <a href="#" id="btndell" class="easyui-linkbutton" iconcls="icon-cancel" onclick="DeleteDialog2()" plain="true">删除二级菜单</a>
        </div>
    </div>
    <div id="editDialog" class="easyui-dialog" style="width: 550px; padding: 10px 0"
         closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            <table cellpadding="5" id="tbledit">
                <tr hidden="hidden">
                    <td class="userinfo-td-l">商品分类ID：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" id="DishesTypeID" name="DishesTypeID" style="width: 300px;" />
                    </td>
                </tr>
                @*<tr>
                        <td class="userinfo-td-l">所属商户：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-validatebox" data-options="required:true" type="text" id="MerID" name="MerID" readonly="true" style="width: 300px;" />
                        </td>
                    </tr>*@
                <tr>
                    <td class="userinfo-td-l">商品一级分类名称：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-validatebox" data-options="required:true" type="text" id="DishesTypeName" name="DishesTypeName" style="width: 300px;" />
                    </td>
                </tr>
                <tr hidden="hidden">
                    <td class="userinfo-td-l">商品标志：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" id="Postion" name="Postion" style="width: 300px;" />
                    </td>
                </tr>
                @*<tr>
                        <td class="userinfo-td-l">备注：</td>
                        <td class="userinfo-td-r">
                            <intput rows="5" class="easyui-textbox" data-optiion="multiline:true" type="text" id="IntBZ" name="IntBZ" style="width: 300px;height:50px;" />
                        </td>
                    </tr>*@
                <tr>
                    <td colspan="2" style="text-align: center; padding-top: 10px;">
                        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="submitForm()">保存</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <div id="editDialog2" class="easyui-dialog" style="width: 550px; padding: 10px 0"
         closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            <table cellpadding="5" id="tbledit">
                <tr hidden="hidden">
                    <td class="userinfo-td-l">商品分类ID：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" id="DishesTypeID" name="DishesTypeID" style="width: 300px;" />
                    </td>
                </tr>
                <tr hidden="hidden">
                    <td class="userinfo-td-l">PantID：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" id="PantID" name="PantID" style="width: 100px;" />
                    </td>
                </tr>
                <tr hidden="hidden">
                    <td class="userinfo-td-l">商品标志：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-textbox" type="text" id="Postion" name="Postion" style="width: 100px;" />
                    </td>
                </tr>
                <tr>
                    <td class="userinfo-td-l">所属一级分类名称：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-validatebox" data-options="required:true" type="text" id="DishesTypeNames" name="DishesTypeName" readonly="true" style="width: 300px;" />
                    </td>
                </tr>
                <tr>
                    <td class="userinfo-td-l">商品二级分类名称：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-validatebox" data-options="required:true" type="text" id="DishesTypeNamess" name="DishesTypeName" style="width: 300px;" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: center; padding-top: 10px;">
                        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="submitForm2()">保存</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <!--图片上传s-->
    <div id="UploadPic" class="easyui-dialog" style="width: 500px; padding: 30px" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <table>
            <tr>
                <td colspan="2" style="text-align: center;">
                    <label id="DishesTypeID_pic" hidden></label>
                    <div id="localImag">
                        <img id="div_img" alt="" onclick="" src="" width="200" height="200" />
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <input id="fileToUpload" style="width: 224px; border: 1px solid #95B8E7" name="pic" multiple="multiple" onchange="fileSelected(this.id,'div_img');" type="file" />
                </td>
                <td>
                    <a id="uploadFile" style="display: none" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="uploadFile()">上传并导入</a>
                </td>
            </tr>
        </table>
    </div>

    <!--工具栏E-->
    <div id="xianshiPic" class="easyui-dialog" style="width:500px;height:400px;" closed="true" modal="true" title="图片" resizable="true">
        <div></div>
        <p id="tishiyu" align="center" style="margin: 0 auto;padding: 10px;">请在图片上选取要上传的部分</p>
        @*<div id="tp1Div" align="center" style="margin:auto;width:300px;padding: 10px;"><img id="tp1" style="border-style:solid; border-width:1px; border-color:#000;" src="~/Content/img/小象.jpg" /></div>*@
        @*<div align="center" style="padding: 10px;"><input type="file" /></div>*@
        <div id="picwenjian"></div>
        <div id="picwenjian1" style="display:none" align="center"><button onclick="quedPic()" style="margin:0px 20px;">确定</button>@*<button style="margin:0px 20px ;">关闭</button>*@</div>
    </div>
</body>
</html>
